package personal.hjj.mybatisdemo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import personal.hjj.mybatisdemo.domain.Student;
import personal.hjj.mybatisdemo.service.StudentService;

import java.util.List;

@Controller
@RequestMapping("/Student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping("list")
    public String list(Model model, @RequestParam(defaultValue = "1") long current, @RequestParam(defaultValue = "3") long size) {
        Page<Student> page = new Page<>(current, size);
        Page<Student> studentPage = studentService.page(page);
        model.addAttribute("students", studentPage.getRecords());
        model.addAttribute("current", studentPage.getCurrent());
        model.addAttribute("pages", studentPage.getPages());
        return "listStudent";
    }
    @RequestMapping("remove")
    public String remove(int id) {
        studentService.removeById(id);
        return "redirect:/Student/list";
    }
}
